<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
<head>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/asserts/backstage/bootrap-table/fresh-bootstrap-table.css" />
	<title>订单管理</title>
</head>
<body>
	<jsp:include page="../frame.jsp" />
	<div class="main-content">
		<div class="main-content-inner">
			<div class="breadcrumbs ace-save-state" id="breadcrumbs">
				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a href="${pageContext.request.contextPath}/statistics">首页</a>
					</li>
					<li class="active">订单管理</li>
				</ul><!-- /.breadcrumb -->
			</div>

			<div class="page-content">
				<div class="page-header">
					<h1>
						订单管理
						<small>
							<i class="ace-icon fa fa-angle-double-right"></i>
							订单列表
						</small>
					</h1>
				</div><!-- /.page-header -->

				<div class="row">
					<div class="col-xs-12 col-sm-12">
						<!-- PAGE CONTENT BEGINS -->
						<div class="row">
							<div class="col-xs-12">
								<div class="table-header">
									订单详情列表
								</div>

								<div class="col-xs-12">
									<h3>${msg}</h3>
									<div class="tab-content table-responsive">
										<c:if test="${fn:length(orders) > 0}">
											<div class="table-responsive">
												<c:forEach items="${orders}" var="order" varStatus="n">
													<table class="table table-bordered">
														<caption>
															订单${n.count} -> 详情
															<c:if test="${order.state == 0}">
																<a href="${pageContext.request.contextPath}/order?method=deleteOrder&oid=${order.oid}" style="color: indianred;">
																	<span>&nbsp;&nbsp; 删除订单 &nbsp;&nbsp;</span>
																</a>
															</c:if>
														</caption>
														<tbody>
														<tr style="font-weight: bold;">
															<td>订单所含商品</td>
															<td>订单状态</td>
															<td>订单金额</td>
															<td>下单时间</td>
															<td>订单编号</td>
														</tr>
														<tr>
															<td style="vertical-align: middle;">
																<table class="table table-bordered" style="text-align: center;">
																	<tbody>
																	<tr style="font-weight: bold;">
																		<td>图片</td>
																		<td>名称</td>
																		<td>单价</td>
																		<td>数量</td>
																		<td>小计</td>
																	</tr>
																	<c:forEach items="${order.orderItems }" var="item">
																		<tr>
																			<td width="60" width="40%" style="vertical-align: middle;">
																				<img src="${pageContext.request.contextPath}/${item.product.pimage}" width="70" height="60">
																			</td>
																			<td width="30%" style="vertical-align: middle;">
																				<a target="_blank" href="${pageContext.request.contextPath}/product?method=productDetails&pid=${item.product.pid}">${item.product.pname}</a>
																			</td>
																			<td width="20%" style="vertical-align: middle;">
																				￥${item.product.shop_price}
																			</td>
																			<td width="20%" style="vertical-align: middle;">
																					${item.count}
																			</td>
																			<td width="15%" style="vertical-align: middle;">
																				<span class="subtotal">${item.subTotal}</span>
																			</td>
																		</tr>
																	</c:forEach>
																	</tbody>
																</table>
															</td>
															<td style="vertical-align: middle;color: red;">
																<c:choose>
																	<c:when test="${order.state == 0}">
																		未付款
																	</c:when>
																	<c:when test="${order.state == 1}">
																		已付款
																	</c:when>
																	<c:when test="${order.state == 2}">
																		已发货
																	</c:when>
																	<c:when test="${order.state == 3}">
																		已完成
																	</c:when>
																</c:choose>
															</td>
															<td style="vertical-align: middle;">
																￥${order.total}
															</td>
															<td style="vertical-align: middle;">
																<%--<fmt:formatDate value="${order.ordertime}" pattern="yyyy-MM-dd hh:mm:ss"></fmt:formatDate>--%>
																${order.ordertime}
															</td>
															<td style="vertical-align: middle;">
																${order.oid}
															</td>
														</tr>
														<c:if test="${order.state != 0}">
															<tr style="font-weight: bold;">
																<td>收货人</td>
																<td>联系电话</td>
																<td>收货地址</td>
																<c:if test="${order.state == 1}">
																	<td rowspan="2" colspan="2" width="10%" style="vertical-align: middle;text-align: center;">
																		<button class="btn btn-danger" onclick="deliveryProduct('${order.oid}')">发货</button>
																	</td>
																</c:if>

																<c:if test="${order.state == 2}">
																	<td rowspan="2" colspan="2" width="10%" style="vertical-align: middle;text-align: center;">
																		订单已完成发货
																	</td>
																</c:if>

																<c:if test="${order.state == 3}">
																	<td rowspan="2" colspan="2" width="10%" style="vertical-align: middle;text-align: center;">
																		订单已完成
																	</td>
																</c:if>
															</tr>
															<tr>
																<td width="30%" style="vertical-align: middle;">
																	${order.name}
																</td>
																<td width="30%" style="vertical-align: middle;">
																	${order.telephone}
																</td>
																<td width="30%" style="vertical-align: middle;">
																	${order.address}
																</td>
															</tr>
														</c:if>
														</tbody>
													</table>
												</c:forEach>
											</div>
										</c:if>
										<c:if test="${fn:length(orders) <= 0}">
											<h3>暂无订单数据，请<a href="${pageContext.request.contextPath}/">接着逛逛</a></h3>
										</c:if>
									</div>
								</div>
							</div>
						</div>
						<!-- PAGE CONTENT ENDS -->
					</div><!-- /.col -->
				</div><!-- /.row -->
				<!-- PAGE CONTENT ENDS -->
			</div>
		</div>
	</div>
</div>
</body>
<script>
	/**
	 * 发货
	 * @param oid
	 */
	function deliveryProduct(oid) {
		window.location.href = '${pageContext.request.contextPath}/orderManage?method=deliveryProduct&oid='+oid;
	}
</script>
</html>